package org.infodavid.common.ejb.components;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.hibernate.annotations.Index;

import org.infodavid.common.dto.IUserGroupListItem;
import org.infodavid.common.dto.IUserListItem;
import org.infodavid.common.dto.IUserGroupListItem.EUserRole;
import org.infodavid.common.ejb.UserBean;
import org.infodavid.common.ejb.UserGroupBean;
import org.infodavid.common.impl.model.security.SecurityIdentifierImpl;
import org.infodavid.common.model.IUser;
import org.infodavid.common.model.IUserGroup;

/**
 * The Class SecurityIdentifierComponent.
 */
@Embeddable
public class SecurityIdentifierComponent extends SecurityIdentifierImpl {

	/** serialVersionUID. */
	private static final long serialVersionUID = 584923281312002876L;

	/**
	 * The Constructor.
	 * @throws Exception the exception
	 */
	protected SecurityIdentifierComponent() throws Exception {
		super();
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.impl.model.security.SecurityIdentifierImpl#getGroup()
	 */
	@Override
	@JoinColumn(name = IUserGroup.ID, referencedColumnName = IUserGroup.ID, nullable = true)
	@ManyToOne(targetEntity = UserGroupBean.class, fetch = FetchType.LAZY)	
	public IUserGroupListItem getGroup() {
		return super.getGroup();
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.impl.model.security.SecurityIdentifierImpl#getUser()
	 */
	@Override
	@JoinColumn(name = IUser.ID, referencedColumnName = IUser.ID, nullable = true)
	@ManyToOne(targetEntity = UserBean.class, fetch = FetchType.LAZY)	
	public IUserListItem getUser() {
		return super.getUser();
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.impl.model.security.SecurityIdentifierImpl#getRole()
	 */
	@Override
	@Enumerated(EnumType.STRING)
	@Column(name = ROLE, nullable = true, length = 32, updatable = false)
	@Index(name = "IDX_ACL_ROLE")
	public EUserRole getRole() {
		return super.getRole();
	}
}
